import { Provide } from "@midwayjs/core";
import { BaseService } from "@cool-midway/core";
import { CapacityEntity } from "../entity/capacity";
import { Equal, Repository } from "typeorm";
import { InjectEntityModel } from "@midwayjs/typeorm";
import { TransportType } from "../entity/type";

@Provide()
export class CapacityService extends BaseService {

    @InjectEntityModel(CapacityEntity)
    capacityModel: Repository<CapacityEntity>

    // 新增运力
    async addCapacity(type: TransportType) {
        return this.capacityModel.save({
            type,
        });
    }

    async getByTeamId(teamId: number, type: TransportType) {
        let capacities = await this.capacityModel.find({
            where: {
                teamId: Equal(teamId),
                type: Equal(type),
            },
        });
        return capacities;
    }
}